package com.ftg.learn.springbootmq.topic.service;

import com.ftg.learn.springbootmq.topic.entity.Product;
import com.ftg.learn.springbootmq.topic.producer.TopicProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProductService {

    @Autowired
    private TopicProducer topicProducer;

    public void createProduct(Product product) {
        product.setProductId("PRODUCT_" + System.currentTimeMillis());
        topicProducer.sendProductMessage("create", product);
    }

    public void deleteProduct(String productId) {
        topicProducer.sendProductMessage("delete", productId);
    }

    public void updateProduct(Product product) {
        topicProducer.sendProductMessage("update", product);
    }
}
